home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / basics / mfc mdiplayer.win / mfcmdiplayerview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.6 KB  |  184 lines

  1. // MFCMDIPlayerView.cpp : implementation of the CMFCMDIPlayerView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MFCMDIPlayer.h"
  6.  
  7. #include "MFCMDIPlayerDoc.h"
  8. #include "MFCMDIPlayerView.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CMFCMDIPlayerView
  18.  
  19. IMPLEMENT_DYNCREATE(CMFCMDIPlayerView, CView)
  20.  
  21. BEGIN_MESSAGE_MAP(CMFCMDIPlayerView, CView)
  22.     //{{AFX_MSG_MAP(CMFCMDIPlayerView)
  23.     ON_WM_CREATE()
  24.     ON_WM_DESTROY()
  25.     ON_WM_SIZE()
  26.     //}}AFX_MSG_MAP
  27.     // Standard printing commands
  28.     ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  29.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  30.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  31. END_MESSAGE_MAP()
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CMFCMDIPlayerView construction/destruction
  35.  
  36. CMFCMDIPlayerView::CMFCMDIPlayerView()
  37. {
  38.     // Create a QuickTime object
  39.     pQuickTime = new CQuickTime;
  40. }
  41.  
  42. CMFCMDIPlayerView::~CMFCMDIPlayerView()
  43. {
  44.     // Destroy the QuickTime object
  45.     if ( pQuickTime ) 
  46.          delete pQuickTime;
  47. }
  48.  
  49. BOOL CMFCMDIPlayerView::PreCreateWindow(CREATESTRUCT& cs)
  50. {
  51.     // TODO: Modify the Window class or styles here by modifying
  52.     //  the CREATESTRUCT cs
  53.  
  54.     return CView::PreCreateWindow(cs);
  55. }
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CMFCMDIPlayerView drawing
  59.  
  60. void CMFCMDIPlayerView::OnDraw(CDC* pDC)
  61. {
  62.     Movie    theMovie;
  63.     CMFCMDIPlayerDoc* pDoc = GetDocument();
  64.     ASSERT_VALID(pDoc);
  65.  
  66.     if (theMovie = pQuickTime->GetMovie())
  67.         UpdateMovie(theMovie);
  68. }
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CMFCMDIPlayerView printing
  72.  
  73. BOOL CMFCMDIPlayerView::OnPreparePrinting(CPrintInfo* pInfo)
  74. {
  75.     // default preparation
  76.     return DoPreparePrinting(pInfo);
  77. }
  78.  
  79. void CMFCMDIPlayerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  80. {
  81.     // TODO: add extra initialization before printing
  82. }
  83.  
  84. void CMFCMDIPlayerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  85. {
  86.     // TODO: add cleanup after printing
  87. }
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CMFCMDIPlayerView diagnostics
  91.  
  92. #ifdef _DEBUG
  93. void CMFCMDIPlayerView::AssertValid() const
  94. {
  95.     CView::AssertValid();
  96. }
  97.  
  98. void CMFCMDIPlayerView::Dump(CDumpContext& dc) const
  99. {
  100.     CView::Dump(dc);
  101. }
  102.  
  103. CMFCMDIPlayerDoc* CMFCMDIPlayerView::GetDocument() // non-debug version is inline
  104. {
  105.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCMDIPlayerDoc)));
  106.     return (CMFCMDIPlayerDoc*)m_pDocument;
  107. }
  108. #endif //_DEBUG
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CMFCMDIPlayerView message handlers
  112.  
  113. BOOL CMFCMDIPlayerView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
  114. {
  115.     // TODO: Add your specialized code here and/or call the base class
  116.     
  117.     return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  118. }
  119.  
  120. int CMFCMDIPlayerView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  121. {
  122.     if (CView::OnCreate(lpCreateStruct) == -1)
  123.         return -1;
  124.     
  125.     // Setup movie window     
  126.      strcpy((char *)pQuickTime->theAppName, AfxGetAppName());  // store app name for window title
  127.  
  128.     pQuickTime->OnMovieWindowCreate( m_hWnd, lpCreateStruct);
  129.     
  130.     return 0;
  131. }
  132.  
  133. void CMFCMDIPlayerView::OnDestroy() 
  134. {
  135.  
  136.     CView::OnDestroy();
  137.         // Destroy movie window
  138.     pQuickTime->OnMovieWindowDestroy();    
  139.  
  140. }
  141.  
  142.  
  143. BOOL CMFCMDIPlayerView::OpenMovie(void)
  144. {
  145.     return pQuickTime->OpenMovie((unsigned char *)(LPCSTR)mfullPath);
  146. }
  147.  
  148. void CMFCMDIPlayerView::CloseMovie(void)
  149. {
  150.     pQuickTime->CloseMovie();
  151. }
  152.  
  153. LRESULT CMFCMDIPlayerView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  154. {
  155.  
  156.     if(message == WM_ERASEBKGND){
  157.  
  158.         LRESULT theResult = CView::WindowProc(message, wParam, lParam);
  159.         pQuickTime->ProcessMovieEvent (m_hWnd, message, wParam, lParam);    
  160.         return theResult;
  161.     } else {
  162.         pQuickTime->ProcessMovieEvent (m_hWnd, message, wParam, lParam);
  163.         return CView::WindowProc(message, wParam, lParam);
  164.     }
  165. }
  166.  
  167. void CMFCMDIPlayerView::OnSize(UINT nType, int cx, int cy) 
  168. {    
  169.     CView::OnSize(nType, cx, cy);
  170.  
  171.     if (cy && cx)
  172.     {
  173.         // calculate the size of the frame
  174.         CFrameWnd* pFrame = GetParentFrame();
  175.         if (pFrame != NULL)
  176.         {
  177.             CRect rectSized(0, 0, cx, cy);
  178.             pFrame->CalcWindowRect(rectSized);
  179.             pFrame->SetWindowPos(this,0,0,rectSized.Width() + 4,rectSized.Height()+ 4, SWP_NOZORDER | SWP_NOMOVE );
  180.  
  181.         }
  182.     }
  183. }
  184.